package com.itheima.controller;

import com.github.pagehelper.Page;
import com.itheima.entity.PageResult;
import com.itheima.entity.Result;
import com.itheima.pojo.Picture;
import com.itheima.pojo.PictureSort;
import com.itheima.service.PictureService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

@RestController
@CrossOrigin
@RequestMapping("/picture")
public class PictureController {

    @Autowired
    private PictureService pictureService;

    /**
     * 批量增
     *
     * @param pictureVOList
     * @return
     */
    @PostMapping("/add")
    public Result add(@RequestBody List<Map> pictureVOList) {
        pictureService.add(pictureVOList);
        return new Result("success", "添加成功");
    }

    /**
     * 改
     *
     * @param pictureVO
     * @return
     */
    @PostMapping("/edit")
    public Result edit(@RequestBody Map pictureVO) {
        pictureService.edit(pictureVO);
        return new Result("success", "编辑成功");
    }

    /**
     * 删
     *
     * @param pictureVO
     * @return
     */
    @PostMapping("/delete")
    public Result delete(@RequestBody Map pictureVO) {
        pictureService.delete(pictureVO);
        return new Result("success", "删除成功");
    }

    /**
     * 查询所有
     *
     * @param pictureVO
     * @return
     */
    @PostMapping("/getList")
    public Result getList(@RequestBody Map pictureVO) {
        PageResult<Picture> pageResult = pictureService.getList(pictureVO);
        return new Result("success", pageResult);
    }

    /**
     * 设为封面
     *
     * @param pictureVO
     * @return
     */
    @PostMapping("/setCover")
    public Result setCover(@RequestBody Map pictureVO) {
        pictureService.setCover(pictureVO);
        return new Result("success", "更新成功");
    }
}
